﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DoAn.DAO
{
    public class DataProvider
    {
        public static string CnStr = ConfigurationManager.ConnectionStrings["SDGCnStr"].ConnectionString;
        //public static string CnStr = @"Server = .\SQLEXPRESS;Integrated Security = True;Database = SanDauGia";
        //public static string CnStr = "Data Source=.;AttachDbFilename=|DataDirectory|\\SanDauGia.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

        public static SqlConnection CreatConnection()
        {
            SqlConnection cn =new SqlConnection(CnStr);
            cn.Open();
            return cn;
        }

        public static DataTable DataTable(string sql)
        {
            SqlConnection cn = new SqlConnection();
            cn = CreatConnection();
            SqlDataAdapter da = new SqlDataAdapter(sql, cn);
            DataTable dt = new DataTable();
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public static void ExcuteQuery(string sql)
        {
            SqlConnection cn = new SqlConnection();
            cn = CreatConnection();
            SqlCommand cmd = new SqlCommand(sql,cn);
            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}